// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.use(BootstrapVue);

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    //console.log("1111")// 判断该路由是否需要登录权限
    //console.log(store.state.token)// 判断该路由是否需要登录权限
    var strorage = localStorage.getItem(prefix + 'token');
    if (!isEmptyObject(strorage)) { // 通过vuex state获取当前的token是否存在
      next();
    } else {
      next({
        path: '/',
        query: { redirect: to.fullPath } // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  } else {
    next();
  }
})


function isEmptyObject(obj) {
  for (let key in obj) {
    return false;
  }
  return true;
}
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
